package com.yzd.netmonitor.util;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 检测空辅助类.
 * @author YRJ
 * @version 1.0.0
 * @see 1.0.0
 *
 */
public final class Check {

	/**
	 * 检测字符串是否为空.
	 * 
	 * @param src test
	 * @return boolean
	 */
	public static boolean NuNString(final String src) {
		return src == null || src.trim().isEmpty();
	}

	/**
	 * 检测一组字符串是否为空.
	 * 
	 * @param src
	 * @return
	 */
	public static boolean NuNString(final String... src) {
		for (String s : src) {
			if (NuNString(s)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 检测对象是否为空.
	 * 
	 * @param obj
	 * @return
	 */
	public static boolean NuNObject(final Object obj) {
		if (obj == null) {
			return true;
		}
		if (obj instanceof String) {
			return NuNString((String) obj);
		}
		return false;
	}

	/**
	 * 检测一组对象是否为空.
	 * 
	 * @param objs
	 * @return
	 */
	public static boolean NuNObject(final Object... objs) {
		for (Object obj : objs) {
			if (NuNObject(obj)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 检测数组是否为空.
	 * 
	 * @param objs
	 * @return
	 */
	public static boolean NuNArray(final Object[] objs) {
		return objs == null || objs.length == 0;
	}

	/**
	 * 检测集合是否为空.
	 * 
	 * @param collection
	 * @return
	 */
	public static boolean NuNCollection(final Collection<?> collection) {
		return collection == null || collection.isEmpty();
	}

	/**
	 * 检测Map是否为空.
	 * 
	 * @param map
	 * @return
	 */
	public static boolean NuNMap(final Map<?, ?> map) {
		return map == null || map.isEmpty();
	}


	/**
	 * 检测List是否为空.
	 * 
	 * @param list
	 * @return
	 */
	public static boolean NuNList(final List<?> list) {
		return list == null || list.size() == 0;
	}
	
	/**
	 * 整数至少有一个相等
	 * @param source
	 * @param others
	 * @return
	 */
	public static  boolean intEqualsLessOne(int source,int ... others){
		for(int i=0;i<others.length;i++){
			if(source==others[i]){
				return true;
			}
		}
		return false;
	}

	private Check() {
		//断言错误 不能实例化类
		throw new AssertionError("Uninstantiable class.");
	}
}
